﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ComicBook.Data.IDataAdapters.Interfaces;
using ComicBook.Data.IDataAdapters.Adapters;
using ComicBook.DataModels;
using ComicBook.web.Models;

namespace ComicBook.web.Controllers
{
    public class AuthorController : Controller
    {
        IComicBookAdapter _adapter;
        public AuthorController()
        {
            _adapter = new ComicBookAdapter();
        }
        public AuthorController(IComicBookAdapter adapter)
        {
            _adapter = adapter;
        }

        public ActionResult AuthorDetail(int id)
        {
            AuthorComicsVM vm = new AuthorComicsVM();
            vm.Author = _adapter.GetAuthor(id);
            vm.Comics = _adapter.GetComicsForAuthor(id);
            
            return View(vm);
        }
        [HttpGet]
        public ActionResult EditAuthor(int id)
        {
            Author author = _adapter.GetAuthor(id);
            return View(author);
        }
        [HttpPost]
        public ActionResult EditAuthor(Author author)
        {
            author = _adapter.UpdateAuthor(author);
            return RedirectToAction("AuthorDetail/"+author.Id);
        }
        
	}
}